package cn.bincker.mycaptcha.letter;

import cn.bincker.mycaptcha.basic.properties.CacheConfigProperties;
import cn.bincker.mycaptcha.basic.properties.ImageCaptchaProperties;
import cn.bincker.mycaptcha.basic.properties.PaddingProperties;
import cn.bincker.mycaptcha.basic.properties.ShadowProperties;
import cn.bincker.mycaptcha.utils.FontUtils;
import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.awt.*;
import java.io.File;
import java.util.List;

@Getter
@Setter
@Component
@ConfigurationProperties("my-captcha.letter")
@ConditionalOnProperty(value = "my-captcha.letter.enable", havingValue = "true")
public class LetterCaptchaProperties implements ImageCaptchaProperties {
    private Boolean enabled = false;
    private String path = "/my-letter-captcha";
    private List<String> protectPathList = DEFAULT_PROTECT_PATH_LIST;
    private File imageFilePath = new File(DEFAULT_IMAGE_PATH);
    private Integer width = 200;
    private Integer height = 60;
    private CacheConfigProperties cache = new CacheConfigProperties(new File(".captcha-cache/letter"));
    private Long survivalTime = 60000L * 5;

    /**
     * 字体列表
     */
    private String[] fonts = FontUtils.getCanDisplayFontFamilyNames();

    /**
     * 最小字母大小
     */
    private Integer minFontSize = ((int)(height * 0.8)) - 6;

    /**
     * 最大字母大小
     */
    private Integer maxFontSize = ((int)(height * 0.8)) + 6;

    /**
     * 边距
     */
    private PaddingProperties padding = new PaddingProperties(0);

    /**
     * 字母数量
     */
    private Integer letterNumber = 4;

    /**
     * 字符字间距
     */
    private Integer letterSpacing = 5;

    /**
     * 最小X轴偏移量
     */
    private Integer minXOffset = 0;

    /**
     * 最大X轴偏移量
     */
    private Integer maxXOffset = 20;

    /**
     * 最小Y轴偏移量
     */
    private Integer minYOffset = 0;

    /**
     * 最大Y轴偏移量
     */
    private Integer maxYOffset = maxFontSize >= height ? 0 : (height - maxFontSize) / 2;

    /**
     * 启用描边
     */
    private Boolean enableStroke = true;

    /**
     * 描边宽度
     */
    private Integer strokeWidth = 5;

    /**
     * 是否镂空,仅在启用描边状态下有效
     */
    private Boolean hollowOut = true;

    /**
     * 最小镂空X轴偏移
     */
    private Integer hollowOutMinOffsetX = 0;

    /**
     * 最大镂空X轴偏移
     */
    private Integer hollowOutMaxOffsetX = 2;

    /**
     * 最小镂空Y轴偏移
     */
    private Integer hollowOutMinOffsetY = 0;

    /**
     * 最大镂空Y轴偏移
     */
    private Integer hollowOutMaxOffsetY = 2;

    /**
     * 外阴影
     */
    private ShadowProperties outsetShadow = new ShadowProperties(true, 0, 0, 0, 10, Color.BLACK);

    /**
     * 内阴影
     */
    private ShadowProperties insetShadow = new ShadowProperties(true, 0, 0, 0, 10, Color.BLACK);

    /**
     * 最小旋转角度
     */
    private Integer minRotateAngle = -60;

    /**
     * 最大旋转角度
     */
    private Integer maxRotateAngle = 60;
}
